<?php
/**
 * Created by JetBrains PhpStorm.
 * User: AndreyG
 * Date: 24.01.12
 * Time: 15:01
 * To change this template use File | Settings | File Templates.
 */
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Задание #1</title>
    <style type="text/css">
        table {text-align: left; border: 1px solid #bbb;}
        table td {border: 1px solid #bbb;}
        .button {display: block; float: left; background: #ddd; padding: 5px; margin: 10px;}
    </style>
    <script type="text/javascript">
        function setLocation(param, value) {
            var url = window.location.href;
            //var url = 'topdetal.ru/index.php?order=8&dir=desc';

            if(-1 == (url.indexOf('?'))) {
                return '?' + param + '=' + value;
            }
            if (-1 < (pos = url.indexOf(param + '='))) {
                return url.replace(new RegExp (param+'=[0-9a-z]*', 'gi'), param + '=' + value);
            } else {
                return url + '&' + param + '=' + value;
            }
            var result = url.match(/\??/gi, 'topdetal.ru/index.php?order=8&dir=desc');
            alert(result);
        }
    </script>
</head>
<body>
<h1>Задание #1: ООП реализация проекта с использованием модели MVC</h1>
      <table>
          <tr>
              <th colspan="4">Фильтры</th>
              <th>
                  <select name="cat" onchange="window.location.href = setLocation(this.getAttribute('name'), this.value)">
                      <option></option>
                      <option value="">- Показать все -</option>
                      <?php
                      foreach($categoryCollection as $category):
                          ?>
                          <option value="<?php echo $category->getId(); ?>"><?php echo $category->getData('title'); ?></option>
                          <?php
                      endforeach;
                      ?>
                  </select>
              </th>
              <th>
                  <select name="location" onchange="window.location.href = setLocation(this.getAttribute('name'), this.value)">
                      <option></option>
                      <option value="">- Показать все -</option>
                      <?php
                      foreach($locationCollection as $location):
                          ?>
                          <option value="<?php echo $location->getId(); ?>"><?php echo $location->getData('title'); ?></option>
                          <?php
                      endforeach;
                      ?>
                  </select>
              </th>
              <th>
                  <select name="sort" onchange="window.location.href = setLocation(this.getAttribute('name'), this.value)">

                      <option value="name" <?php if($params['sort'] == 'name') echo 'selected';?>> По названию</option>
                      <option value="rating" <?php if($params['sort'] == 'rating') echo 'selected';?>> По рейтингу</option>
                  </select>
                  <?php
                  if($params['dir'] == 'asc'):
                      ?>
                      <a href="#" onclick="window.location.href = setLocation('dir', 'desc')">< &darr; ></a>
                      <?php
                  elseif($params['dir'] == 'desc'):
                      ?>
                      <a href="#" onclick="window.location.href = setLocation('dir', 'asc')">< &uarr; ></a>
                      <?php
                  endif;
                  ?>
              </th>
          </tr>
          <tr>
              <td><strong>Рейтинг</strong></td>
              <td><strong>Компания</strong></td>
              <td><strong>Описание</strong></td>
              <td><strong>Телефон</strong></td>
              <td><strong>Email</strong></td>
              <td><strong>Город</strong></td>
              <td><strong>Категории</strong></td>
          </tr>

          <?php foreach($companyCollection as $company): ?>
          <tr>
              <td><?php echo $company->getData('rating'); ?></td>
              <td><?php echo $company->getData('name'); ?></td>
              <td><?php echo $company->getData('short_desc'); ?></td>
              <td><?php echo $company->getData('phone'); ?></td>
              <td><?php echo $company->getData('email'); ?></td>
              <td><?php echo $company->getData('location'); ?></td>
              <td><?php echo $company->getData('category'); ?></td>
          </tr>
          <?php endforeach; ?>
          <tr>
              <td colspan="7">
                  <a href="http://redmarks.ru/htdocs/index.php/company/add/" class="button">Добавить компанию</a>
                  <a href="http://redmarks.ru/htdocs/" class="button">Сбросить фильтры</a>
              </td>
          </tr>
      </table>

		<p style="font-size: 0.8em">This page was rendered in {TMVC_TIMER} seconds.</p>

	</body>
</html>


